var $ = require('jquery');


function Slide(elems,paginates){
  var self = this;

  self.currentIndex = 0;
  this.elems = $(elems);
  this.current = $(this.elems[0]);
  this.paginates = $(paginates);
  this.paginates.each(function(i,el){
    $(el).click(function(){
      self.to(i);
    });
  });
}

Slide.prototype.to = function(index){
  var self = this;
  var next = this.elems.eq(index);
  this.current.fadeOut();
  next.fadeIn(function(){
    self.paginates.removeClass("active");
    self.paginates.eq(index).addClass("active");
    self.current = next;
    self.currentIndex = index;
  }); 
}


var slide = new Slide(".slide-container .item", ".paginate .dot");
setInterval(function(){
  var next = slide.currentIndex + 1;
  if(next >= $(".paginate .dot").length){
    next = 0;
  }
  slide.to(next);
},4000);

// var leftnavs = $(".leftnav a");
// leftnavs.each(function(i,el){
//   $(el).click(function(){
//     slide.to(i);
//   });
// });


// $(".features li").each(function(i,el){
//   $(el).click(function(){
//     slide.to(i+leftnavs.length);
//   });
// });